/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.UserstaffEntity;
import java.sql.Types;
import java.util.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
public class UserstaffMapperImpl  {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.selectAll
    
    public List<UserstaffEntity> selectAll() {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_Userstaff where `status`=1;\n";
        
        ResultSetProcessor processor = new AutoBeanListProcessor(new UserstaffEntity());
        return (List<UserstaffEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.selectByTenantId
    
    public List<UserstaffEntity> selectByTenantId(String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_Userstaff where `status`=1 and `ytenant_id`=?;\n";
        parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanListProcessor(new UserstaffEntity());
        return (List<UserstaffEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.SelectByUserId
    
    public UserstaffEntity SelectByUserId(String yhtUserId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_Userstaff where `yhtUserId`=? limit 1;\n";
        parameter.addParam(yhtUserId);

        ResultSetProcessor processor = new AutoBeanProcessor(new UserstaffEntity());
        return (UserstaffEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.SelectByTenantKey
    
    public UserstaffEntity SelectByTenantKey(String tenantId, String yhtUserId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_Userstaff where `yhtUserId`=? and `ytenant_id`=? limit 1;\n";
        parameter.addParam(yhtUserId);
		parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanProcessor(new UserstaffEntity());
        return (UserstaffEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(UserstaffEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxqyy_Userstaff set `yhtUserId` = ?, `userName` = ?, `trueName` = ?, `mobile` = ?, `password` = ?, `modify_time` = ?, `modifier` = ?, `ytenant_id` = ?, `tenantName` = ?, `dr` = ?, `status` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getYhtUserId(), Types.VARCHAR);
		parameter.addParamWithType(record.getUserName(), Types.VARCHAR);
		parameter.addParamWithType(record.getTrueName(), Types.VARCHAR);
		parameter.addParamWithType(record.getMobile(), Types.VARCHAR);
		parameter.addParamWithType(record.getPassword(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifyTime(), Types.TIMESTAMP);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenantName(), Types.VARCHAR);
		parameter.addParamWithType(record.getDr(), Types.INTEGER);
		parameter.addParamWithType(record.getStatus(), Types.INTEGER);
		parameter.addParamWithType(record.getId(), Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.insert
    
    public int insert(UserstaffEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxqyy_Userstaff (`id`, `yhtUserId`,  `userName`, `trueName`,  `mobile`, `password`,  `create_time`, `modify_time`,  `creator`, `modifier`,  `status`, `dr`, `ytenant_id`,`tenantName`) values (?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?,?, ?)\n";
        parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getYhtUserId(), Types.VARCHAR);
		parameter.addParamWithType(record.getUserName(), Types.VARCHAR);
		parameter.addParamWithType(record.getTrueName(), Types.VARCHAR);
		parameter.addParamWithType(record.getMobile(), Types.VARCHAR);
		parameter.addParamWithType(record.getPassword(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreateTime(), Types.TIMESTAMP);
		parameter.addParamWithType(record.getModifyTime(), Types.TIMESTAMP);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getStatus(), Types.INTEGER);
		parameter.addParamWithType(record.getDr(), Types.INTEGER);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenantName(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.selectCount
    
    public int selectCount(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxqyy_Userstaff where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(Long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxqyy_Userstaff where `id` = ?\n";
        parameter.addParamWithType(id, Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.selectById
    
    public UserstaffEntity selectById(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_Userstaff where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new UserstaffEntity());
        return (UserstaffEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.SelectByMobile
    
    public UserstaffEntity SelectByMobile(String tenantId, String mobile) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_Userstaff where `mobile`=? and `ytenant_id`=? limit 1;\n";
        parameter.addParam(mobile);
		parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanProcessor(new UserstaffEntity());
        return (UserstaffEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.selectAllByMobile
    
    public List<UserstaffEntity> selectAllByMobile(String mobile) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_Userstaff where `status`=1 and mobile=?;\n";
        parameter.addParam(mobile);

        ResultSetProcessor processor = new AutoBeanListProcessor(new UserstaffEntity());
        return (List<UserstaffEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.UserstaffMapper.selectUserListByYhtUserIds
    
    public List<UserstaffEntity> selectUserListByYhtUserIds(String[] ids, String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select id, yhtUserId, userName, trueName, mobile from dxqyy_Userstaff where dr!=1 and ytenant_id=? ");
		parameter.addParam(tenantId);
		if (CollectionUtil.isNotEmpty(ids)) {
			sqlBuilder.append(" and yhtUserId in ( ");
			int index = 0;
			String separator0 = " , ";
			for (String item : ids) {
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < ids.length - 1) {
					sqlBuilder.append(separator0);
				}
				index++;
			}
			sqlBuilder.append(" ) ");
		}

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new UserstaffEntity());
        return (List<UserstaffEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

}
